nums=list(map(int,input().split()))
nums.pop()

result=0
score=0
for num in nums:
    if num==1:
        score=1
    else:
        if score==1:
            score=2
        else:
            score+=2
    result+=score

print(result)